//
//  Bridge.m
//  Charles
//
//  Created by Leo on 2019/6/21.
//  Copyright © 2019 charles. All rights reserved.
//

#import "Bridge.h"

@implementation Ape {
    @protected
    ApeBehavior *_behavior; // 这个变量就是桥接模式中的桥梁:用来连接 "类的功能层次结构" 和 "类的实现层次结构"
}

- (instancetype)initWithApeBehavior:(ApeBehavior *)behavior {
    if (self = [super init]) {
        _behavior = behavior;
    }
    return self;
}

- (void)eat {
    [_behavior apeEat];
}

- (void)walk {
    [_behavior apeWalk];
}

@end

@implementation Monkey

- (void)eat {
    [super eat];
}

- (void)walk {
    [super walk];
}

- (void)speak {
    NSLog(@"Monkey speak!");
}

@end


@implementation ApeBehavior {
    @protected
    NSString *_title;
}

- (instancetype)initWithTitle:(NSString *)title {
    if (self = [super init]) {
        _title = title;
    }
    return self;
}

- (void)apeEat {
}

- (void)apeWalk {
}

@end

@implementation MonkeyBehavior

- (void)apeEat {
    NSLog(@"ape eat %@",_title);
}

- (void)apeWalk {
    NSLog(@"ape walk %@",_title);
}

@end
